package com.example.voucher.common;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;

public class DateUtils {

    public static Date getLastDayOfMonth(Date date) {
        LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        localDate = localDate.with(TemporalAdjusters.lastDayOfMonth());
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }
    
    public static String getFormatDate(Date date, String pattern) {
        String format = DateFormatUtils.format(date, pattern);
        return format;
    }

    public static String getPeriod(Date date) {
        String format = DateFormatUtils.format(date, "yyyyMM");
        return format;
    }

    public static String getMonth(Date date) {
        String format = DateFormatUtils.format(date, "MM");
        return format;
    }

    public static String getYear(Date date) {
        String format = DateFormatUtils.format(date, "yyyy");
        return format;
    }

}
